package com.example.brazil_project.function;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import com.example.brazil_project.DucumentActivity;
import com.example.brazil_project.IndexActivity;
import com.example.brazil_project.MainActivity;
import com.example.brazil_project.parameter.Parameter;
import com.example.brazil_project.util.HttpUtil;
import com.example.brazil_project.util.IOUtil;
import com.example.brazil_project.util.ImageCutUtil;
import com.example.brazil_project.util.JSFunction;
import com.example.brazil_project.util.ParameterUtil;
import com.example.brazil_project.util.SharedPreferencesUtil;
import com.example.brazil_project.util.StringUtils;
import com.example.brazil_project.util.WebviewSetting;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.webkit.WebView;

public class UpdateProfileFunction {
	Activity mContxt; 
	Object view; 
	 public UpdateProfileFunction(Activity mContxt,Object view) {  
	        this.mContxt = mContxt;  
	        this.view = view;
	       
	  }  
	
	 
	 /** 修改**/
	 public String updateUserProfile(String data){
		 //String url = Parameter.getServerPath()+"APP/user/updateUserProfile.nut?"+data;
		 String url = Parameter.getServerPath()+"APP/user/updateUserProfile.nut";
		 Map map = ParameterUtil.getParameter(data);
		 WebView webview = (WebView) view;
		 String img_name = (String) map.get("img_name");
		 List<NameValuePair> params = new ArrayList<NameValuePair>(); 
		 if(!StringUtils.isBlank(img_name)){
			 
//			 File file = new File(img_name);
//			 Long filesize = file.length()/1023L;
//			 if(filesize>=200L){
//				 int scale = (int) (filesize/100L);
//				 String result = img_name.replace(".", "1.");
//				 ImageCutUtil.scale(img_name, result, scale, false);
//				 
//				 img_name = 1+img_name;
//			 }
//			
			 
			
			 
			 String FiletoString =IOUtil.FiletoString(img_name,true);
			 params.add(new BasicNameValuePair("img_Stream",FiletoString));  
			 map.put("img_Stream", FiletoString);
			 
			
		
		
		 }
		  
    	
		
		 String msg = HttpUtil.doPost(url,map);
		
		
		 if(msg.equals("-1")){
			 msg = "修改失败"; 
			 webview.loadUrl(JSFunction.getAlertMSGFunction(msg)); 	
		 }
		 else{
			 mContxt.finish();
		 } 
		 return msg; 
	 }
	 

	 
	
	
}
